package com.run.web.backend;


import com.run.model.EbOrder;
import com.run.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/list")
    public String list(Model model,
                       @RequestParam(value = "page",defaultValue = "1") int page,
                       @RequestParam(value = "pageSize",defaultValue = "3") int pageSize){
        System.out.println("进入Order");

        List<EbOrder> ebOrders = orderService.list(page,pageSize);
        model.addAttribute("ebOrder",ebOrders);
        return "manage/order";
    }

    @RequestMapping("/to_eoid")
    public String toeoid(Model model, @RequestParam("eoid")int eoid){
        System.out.println("点击修改了。eoid="+eoid);
        EbOrder ebOrder = orderService.selectOne(eoid);
        model.addAttribute("ebOrder",ebOrder);
        System.out.println(model.addAttribute("ebOrder",ebOrder));
        return  "manage/order-modify";
    }
    @RequestMapping("/eoit")
    public String eoit(EbOrder ebOrder){
        Integer reault = orderService.updateOrder(ebOrder);
        if(reault<1){
            return "manage/manage-error";
        }
        return "manage/manage-result";
    }

    @RequestMapping("/delet")
    public String delet(Model model,@RequestParam("eoid")int eoid){
        int result  = orderService.deltOrder(eoid);
        model.addAttribute("ebOrder",result);
        if (result<1){
            return "manage/manage-error";
        }
        return "manage/manage-result";
    }

}
